﻿using System.Windows.Forms;
using CSW.Framework.Common;
using CSW.Framework.Common.Exceptions;

namespace CSW.Framework.UI.DevEx.Forms
{
    /// <summary>
    /// DXProgressForm.
    /// </summary>
    public static class DXProgressFormVoid
    {
        /// <summary>
        /// Runs the specified asynchronous process delegate.
        /// </summary>
        /// <param name="method">The async process delegate.</param>
        /// <param name="message">The message.</param>
        public static void Run(MethodInvoker method, string message)
        {
            Run(method, message, ExceptionHelper.ShowException, null);
        }

        /// <summary>
        /// Runs the specified asynchronous process delegate.
        /// </summary>
        /// <param name="method">The async process delegate.</param>
        /// <param name="message">The message.</param>
        /// <param name="exceptionHandler">The exception handler.</param>
        public static void Run(MethodInvoker method, string message, ExceptionHandlerDelegate exceptionHandler)
        {
            Run(method, message, exceptionHandler, null);
        }

        /// <summary>
        /// Runs the specified asynchronous process delegate.
        /// </summary>
        /// <param name="method">The async process delegate.</param>
        /// <param name="message">The message.</param>
        /// <param name="exceptionHandler">The exception handler.</param>
        /// <param name="owner">Shows the progress form with the specified owner.</param>
        public static void Run(MethodInvoker method, string message, ExceptionHandlerDelegate exceptionHandler, IWin32Window owner)
        {
            DXProgressForm<MethodInvoker, string, object>.Run(Run2, method, message, exceptionHandler, owner);
        }

        private static object Run2(AsyncProcessHelper helper, MethodInvoker method, string message)
        {
            helper.UpdateStatus(message);
            method();

            return null;
        }
    }
}
